import { createParamDecorator, ExecutionContext } from "@nestjs/common";

export const UserRoles = createParamDecorator(
    async (_: unknown, ctx: ExecutionContext) => {
        const request = ctx.switchToHttp().getRequest().user.roles;
        if (!request) {
            throw new Error("Can't read user roles from user, please check @RequireRoles")
        }
        const userRoles = request.map((item) => item.roleName) || [];
        return userRoles.join(';');
    },
);